package com.gln.bloger.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.gln.bloger.constant.Constant;
import com.gln.bloger.pojos.Website;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedOutput;

public class RssAction extends BaseAction {
	
	public ActionForward rss(ActionMapping mapping, ActionForm  form, 
			HttpServletRequest request, HttpServletResponse response) throws Exception{
		Website currentWebsite = getAuthWebsite(request);
		
		String bloggerPath = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf("/"))+"/"+currentWebsite.getHandle();
		SyndFeed feed = getEntryService().getRssFeed(getAuthWebsite(request), Constant.DEFAULT_FEED_TYPE, bloggerPath);
		feed.setTitle(currentWebsite.getName());
		feed.setLink(bloggerPath);
		feed.setDescription(currentWebsite.getDescription());
		
		response.setContentType(Constant.MIME_TYPE);
		SyndFeedOutput output = new SyndFeedOutput();
		response.setHeader("Pragma","No-Cache");
		response.setHeader("Cache-Control","No-Cache");
		response.setDateHeader("Expires",0);
		output.output(feed, response.getWriter());
		return mapping.findForward("/entry.do&amp;method=list&amp;handle="+currentWebsite.getHandle()+"/");
	}

}
